// pages/user/user.js
var util = require("../../utils/util.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: '',
        isShowFreight: !1,
        type: 0,
        prizeList:[],
        imgList:[
        'http://hi.lengjishan.cn/new/resource/bibifan/left_up.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/middle_up.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/right_up.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/middle_right.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/right_down.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/middle_down.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/left_down.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/left_middle.png'
        ],
        imgActiveList:[
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_left_up.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_up.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_right_up.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_right_middle.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_right_down.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_middle_down.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_left_down.png',
        'http://hi.lengjishan.cn/new/resource/bibifan/prize_left_middle.png'
        ],
        cjChange:null,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.getPrizeList();
    },
    onShow: function() {
        const _this = this;
        const userInfo = wx.getStorageSync('userInfo');
        _this.setData({
            userInfo
        });
    },
    getUserInfo: function(e) {
        this.setData({
            userInfo: e.detail.userInfo
        })
    },
    toCoupon: function() {
        if(this.data.userInfo){
            wx.navigateTo({
                url: '/pages/coupon/coupon'
            })
        }else{
            this.login.openLoginModal();
        }
    },
    toVoucher: function() {
        if(this.data.userInfo){
            wx.navigateTo({
                url: '/pages/voucher/voucher'
            })
        }else{
            this.login.openLoginModal();
        }
    },
    toCollect: function() {
        if(this.data.userInfo){
            wx.navigateTo({
                url: '/pages/follow/follow'
            })
        }else{
            this.login.openLoginModal();
        }
    },
    toPresent: function() {
        if(this.data.userInfo){
            wx.navigateTo({
                url: '/pages/order-list/order-list?id='+ 0
            })
        }else{
            this.login.openLoginModal();
        }
    },
    toCard: function() {
        if(this.data.userInfo){
            wx.navigateTo({
                url: '/pages/card-list/card-list'
            })
        }else{
            this.login.openLoginModal();
        }
    },
    toOrder: function(e) {
        if(this.data.userInfo){
            let sts = e.currentTarget.dataset.sts;
            wx.navigateTo({
                url: '/pages/order-list/order-list?id='+ e.currentTarget.dataset.id
            })
        }else{
            this.login.openLoginModal();
        }
    },
    getPrizeList: function () {
        const _this = this;
        util.request(getApp().api.prize.getPrizeList).then(
            function(res) {
                if (res.code == 200) {
                    _this.setData({
                        prizeList: res.data,
                        priceCount: res.data2
                    })
                } else {
                    wx.showToast({
                        title: res.msg, //提示的内容,
                        icon: "none", //图标,
                        //duration: 1500, //延迟时间,
                        mask: false, //显示透明蒙层，防止触摸穿透,
                    });
                    setTimeout(function() {
                        wx.hideToast();
                    }, 1500);
                    return
                }
            }
        );
    },
    toPrize: function () {
        const _this = this;
        util.request(getApp().api.prize.toPrize,{orderId:'060809093328121'}).then(
            function(res) {
                if (res.code == 200) {
                    _this.setData({
                        prizeRes: res.data,
                        type:1
                    });
                } else {
                    wx.showToast({
                        title: res.msg, //提示的内容,
                        icon: "none", //图标,
                        //duration: 1500, //延迟时间,
                        mask: false, //显示透明蒙层，防止触摸穿透,
                    });
                    setTimeout(function() {
                        wx.hideToast();
                    }, 1500);
                    return
                }
            }
        );
    },
    confirm: function() {
        this.setData({
            isShowFreight: !1
        });
    },
    toLogin: function() {
        this.login.openLoginModal();
    },
    onReady:function () {
        this.login = this.selectComponent('#login');
    }
})